define(function(require, exports, module) {
	require("oa/act/main/css/abstractStatistics.css");
	require("resource/css/oaPanel.css");
	var ajax = require("resource/js/component/ajax.js");
	var params = {};
	var separator="@VITO@";
	exports.init = function(userId) {
		using(["parser", "layout", "dialog", "panel", "datagrid", "textbox",
			"combobox", "datetimebox", "accordion", "numberbox",
			"linkbutton"
		], function() {
			var date = new Date();
			var dateEnd = new Date(date.getFullYear(), date.getMonth() + 1 ,0);
			var seperator1 = "/";
			$('#hisTitle').text($('.panel-title').text() + '历史');
			$('#processName').text($('.panel-title').text());
			params.processKey = $('#processKey').val();
			params.startTime = date.getFullYear() + seperator1 + (date.getMonth() + 1) + seperator1 + "1";
			params.endTime = dateEnd.getFullYear() + seperator1 + (dateEnd.getMonth() + 1) + seperator1 + dateEnd.getDate();
			//params.userId = indexApp.currentUser.userId;
			var userId = $('#startUser').val()||$('#currentUserId').val();
			params.userId = userId
			getHistoricalTotal();
			getHistoricalDate();
		});
	}

	function getHistoricalTotal() {
		ajax.init().success(function(code, msg, data) {
			$('#histTotal').text(data + $('#historicalData').data('unit'));
		}).post(BASEPATH + "/oa/act/statistics/getProcessStatisticData.htm", params);
	}

	function getHistoricalDate() {
		ajax.init().success(function(code, msg, data) {
			if (null == data || undefined == data) {
				return;
			}
			$('#histTimes').text(data.total)

			$.each(data.rows, function(i, row) {
				var infos = row.abstract.split(separator);
				var background="";
				if(1 == i%2){
					background="background:#f4f9ff"
				}
				var htmlStr='<div id="item'+i+'" class="item" style="width: 100%;height: auto;padding-top: 1px;padding-bottom: 7px;'+background+'"> <div id="index" style="float: left;text-align:left;font-size: 20px;vertical-align: middle;margin-left: 7px;"><p id="index" style="color: #666666;line-height: 50px;">'+(i+1)+'.'+'</p></div> <div id="detail" style="float: left;margin-left: 25px;"> <table style="text-align: left;">';
					$.each(infos, function(index, info) {
						var subInfo = info.split("：");
						if(subInfo.length == 2)
						htmlStr = htmlStr +'<tr id="info'+index+'" style="font-size: 16px;"><th><span style="text-align: left;padding-right: 55px;color: #666666;width="";>'+subInfo[0]+'</span></th><th><span class="justify">'+subInfo[1]+'</span></th></tr>'
					});
					htmlStr += '</table></div> <div id="id4" style="clear:both"></div> </div> <div style="border-bottom: 1px solid #85b9ef;"></div>';
				$(htmlStr).appendTo('#list');

			});
		}).post(BASEPATH + "/oa/act/statistics/getProcessAbstractList.htm", params);
	}

});